﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CrmWorkflowDependencies.Dependencies
{
    public class Vertex
    {
        private static int _hashcodecounter = 0;

        public string Url { get; set; }

        public bool Track { get; set; }

        public Dictionary<string, object> Properties = new Dictionary<string, object>();

        public componenttype Type { get; set; }

        public Guid ID { get; set; }
        public string Alias { get; set; }
        public virtual string Label { get; set; }

        public Vertex(string alias, string label = null)
        {
            Alias = alias;
            if (string.IsNullOrEmpty(label))
            {
                Label = alias;
            }
            else
            {
                Label = label;
            }
        }

        public Vertex(Guid id, string label)
        {
            ID = id;
            Alias = id.ToString();
            Label = label;
        }

        public override bool Equals(object obj)
        {
            Vertex v = (Vertex)obj;
            return this.ID == v.ID && this.Alias == v.Alias && v.GetType() == this.GetType() && this.Type == v.Type /// 1ый уровень
                && (!(v is VertexProperty) || (((VertexProperty)v).Parent != null && ((VertexProperty)v).Parent.Equals(((VertexProperty)this).Parent))); /// родители
        }

        private int _hashcode = _hashcodecounter++;

        public override int GetHashCode()
        {
            return 0;
        }
    }

    public class MyEdge : QuickGraph.Edge<Vertex>
    {
        public string PortFrom { get; private set; }
        public string PortTo { get; private set; }

        public string Label { get; private set; }

        public MyEdge(Vertex vertexFrom, string label, Vertex vertexTo) : this(vertexFrom, vertexTo)
        {
            this.Label = label;
        }

        public MyEdge(Vertex vertexFrom, string portFrom, Vertex vertexTo, string portTo) : base(vertexFrom, vertexTo) {
            PortFrom = portFrom;
            PortTo = portTo;
        }

        public MyEdge(Vertex vertexFrom, Vertex vertexTo) : base(vertexFrom, vertexTo) { }
    }

    public class CategoryEdge : MyEdge
    {
        public string Category { get; private set; }

        public CategoryEdge(Vertex vertexFrom, string category, Vertex vertexTo) : base(vertexFrom, vertexTo) {
            this.Category = category;
        }
    }
}
